import datetime
from django.db import models
from django.db.models import Q


class PublicableManager(models.Manager):
    def get_query_set(self):
        return super(PublicableManager, self).get_query_set().filter(in_range, is_public=True)


class DatePublicableManager(models.Manager):
    def get_query_set(self):
        queryset = super(DatePublicableManager, self).get_query_set()
        now = datetime.datetime.now()
        in_range = Q(pub_date__lte=now) & (Q(pub_end_date__isnull=True) | Q(pub_end_date__gte=now))
        return queryset.filter(in_range, is_public=True)
